<template>
	<view class="detail">
		<view class="title">{{detailArr.title}}</view>
		<view class="info">
			<view class="author">编辑：{{detailArr.author}}</view>
			<view class="time">发布日期：{{detailArr.posttime}}</view>
		</view>
		<view class="content">
			<rich-text :nodes="detailArr.content"></rich-text>			
		</view>
		<view class="description">
			声明：本站的内容均采集与腾讯新闻，如果侵权请联系管理（513894357@qq.com）进行整改删除，本站进行了内容采集不代表本站及作者观点，若有侵犯请及时联系管理员，谢谢您的支持。
		</view>
	</view>
</template>

<script>
	import {parseTime} from "@/utils/tool.js"
	
	
	export default {
		data() {
			return {
				cid:50,
				id:259,
				detailArr:{}
			};
		},
		onLoad(e){			
		console.log(e);
		this.cid=e.cid
		this.id=e.id
		this.getDetailContent()
		},
		methods:{
			getDetailContent(){
				uni.showLoading({
					title: '加载中'
				})
				uni.request({
					url:'https://ku.qingnian8.com/dataApi/news/detail.php',
				data:{
					cid:this.cid,
					id:this.id
				},
				success:(res) =>{
					console.log(res);
					uni.hideLoading()
					res.data.posttime=parseTime(res.data.posttime)
					res.data.content=res.data.content.replace(/<img/gi,'<img style="max-width:100%"')
					this.detailArr=res.data
					this.saveHistory()
					uni.setNavigationBarTitle({
						title:this.detailArr.title
					})
				}
				})
			},
			saveHistory(){
				let history=uni.getStorageSync('history')||[]
				let item={
					id:this.detailArr.id,
					cid:this.detailArr.classid,
					title:this.detailArr.title,
					picurl:this.detailArr.picurl,
					looktime:parseTime(Date.now())
					
				}
				let index=history.findIndex((i)=>{
					return i.id==this.detailArr.id
				})
				if(index>=0){
					history.splice(index,1)
				}
				history.unshift(item)
				history=history.splice(0,10)
				uni.setStorageSync('history',history)
				console.log(uni.getStorageSync('history'));
			}
		},
	}
</script>

<style lang="scss">
.detail{
	padding:30rpx;
	.title{
		font-size: 46rpx;
		color:#333;
	}
	.info{
		background: #F6F6F6;
		padding:20rpx;
		font-size: 25rpx;
		color:#666;
		display: flex;
		justify-content: space-between;
		margin:40rpx 0;
	}
	.content{
		padding-bottom:50rpx;		
	}
	.description{
		background: #FEF0F0;
		font-size: 26rpx;
		padding:20rpx;
		color:#F89898;
		line-height: 1.8em;
	}
}
</style>
